﻿Imports ACompany.OrderProcessing.Model
Imports NUnit.Framework

<TestFixture()> _
Public Class CustomerTests

    <Test()> _
    Public Sub A_Customer_Is_Not_Valid_Unless_He_Has_An_Address()

        Dim aCustomer As New Customer
        aCustomer.Name = "Mr Test"
        aCustomer.Email = "MrTest@Test.com"

        Assert.IsTrue(ContainsBrokenRules("A Customer must have an address", aCustomer.GetBrokenRules))
    End Sub

    <Test()> _
    Public Sub A_Customers_Email_Address_Has_To_Be_No_Greater_Than_50_Chars_Otherwise_The_Customer_Is_Invalid()

        Dim aCustomer As New Customer
        aCustomer.Name = "Mr Test"
        aCustomer.Email = "MrTest@Testrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.com"

        Assert.IsTrue(ContainsBrokenRules("Email should be 50 chars or less", aCustomer.GetBrokenRules))
    End Sub

    <Test()> _
   Public Sub A_Customers_Name_Has_To_Be_No_Greater_Than_50_Chars_Otherwise_The_Customer_Is_Invalid()

        Dim aCustomer As New Customer
        aCustomer.Name = "Mr Test xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        aCustomer.Email = "MrTest@Test.com"

        Assert.IsTrue(ContainsBrokenRules("Name should be 50 chars or less", aCustomer.GetBrokenRules))
    End Sub

    <Test()> _
    Public Sub A_Customer_Is_Valid_If_They_Have_No_Broken_Rules()

        Dim aCustomer As New Customer
        Dim anAddress As New Address("My Street", "My City", "My County", "Post Code")

        aCustomer.Name = "Mr Test"
        aCustomer.Email = "MrTest@test.com"

        aCustomer.Address = anAddress

        Assert.AreEqual(0, aCustomer.GetBrokenRules.Count)
    End Sub

    Private Function ContainsBrokenRules(ByVal ExpectedBrokeRule As String, ByVal ListOFBrokenRules As IList(Of Infrastructure.BrokenRule)) As Boolean

        For Each brokenRule As Infrastructure.BrokenRule In ListOFBrokenRules
            If ExpectedBrokeRule = brokenRule.Rule Then
                Return True
            End If
        Next

        Return False

    End Function


End Class
